﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ComputerArchitecture.Core.Logging;
using ComputerArchitecture.Numbers;
using ComputerArchitecture.Units.Float;
using ComputerArchitecture.Units.Interfaces;

namespace ComputerArchitecture.Lab5
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Aleksey Suharev float-point number multiply emulator 2013 @ p4s software group");
            Console.WriteLine("Choose number format: 1 - float (32 bits); 2 - double (64 bits)");
            int format = int.Parse(Console.ReadLine());
            Func<object, IFloatPointNumber> createNumber;
            Func<IFloatPointNumber, object> toNumber;
            Func<string, object> parseString;
            if (format == 1)
            {
                createNumber = d => ((float)d).ToFloatPointNumber();
                toNumber = f => f.ToFloat();
                parseString = s => float.Parse(s, NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            else
            {
                createNumber = d => ((double)d).ToDoublePointNumber();
                toNumber = f => f.ToDouble();
                parseString = s => double.Parse(s, NumberStyles.Float, CultureInfo.InvariantCulture);
            }
            Console.Write("Enter first value: ");
            object first = parseString(Console.ReadLine());
            Console.Write("Enter second value: ");
            object second = parseString(Console.ReadLine());
            IFloatPointNumber firstNumber = createNumber(first), secondNumber = createNumber(second);


            ILoggingService log = new NLogFacadeLoggingService("logService");
            IFloatPointNumber result = null;
            IFloatMultiplyUnit multiplyUnit = new FloatMultiplyUnit(log);
            result = multiplyUnit.Multiply(firstNumber, secondNumber);

            Console.WriteLine("Result: {0} ({1:f10})", result, toNumber(result));
        }
    }
}
